{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"https://raw.githubusercontent.com/Qiskit/qiskit-tutorials/master/images/qiskit-heading.png\" alt=\"Note: In order for images to show up in this jupyter notebook you need to select File => Trusted Notebook\" width=\"500 px\" align=\"left\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## _*Superposition*_ \n",
    "\n",
    "\n",
    "The latest version of this notebook is available on https://github.com/qiskit/qiskit-tutorial.\n",
    "\n",
    "***\n",
    "### Contributors\n",
    "Jay Gambetta, Antonio Córcoles, Andrew Cross, Anna Phan\n",
    "\n",
    "### Qiskit Package Versions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'qiskit': '0.10.3',\n",
       " 'qiskit-terra': '0.8.1',\n",
       " 'qiskit-ignis': '0.1.1',\n",
       " 'qiskit-aer': '0.2.1',\n",
       " 'qiskit-ibmq-provider': '0.2.2',\n",
       " 'qiskit-aqua': '0.5.1'}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import qiskit\n",
    "qiskit.__qiskit_version__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Introduction\n",
    "Many people tend to think quantum physics is hard math, but this is not actually true. Quantum concepts are very similar to those seen in the linear algebra classes you may have taken as a freshman in college, or even in high school. The challenge of quantum physics is the necessity to accept counter-intuitive ideas, and its lack of a simple underlying theory. We believe that if you can grasp the following two Principles, you will have a good start: \n",
    "1. A physical system in a definite state can still behave randomly.\n",
    "2. Two systems that are too far apart to influence each other can nevertheless behave in ways that, though individually random, are somehow strongly correlated.\n",
    "\n",
    "In this tutorial, we will be discussing the first of these Principles, the second is discussed in [this other tutorial](entanglement_introduction.ipynb)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:21:10.790300Z",
     "start_time": "2018-09-29T01:21:10.782117Z"
    }
   },
   "outputs": [],
   "source": [
    "# useful additional packages \n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "import numpy as np\n",
    "\n",
    "# importing Qiskit\n",
    "from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute\n",
    "from qiskit import BasicAer, IBMQ\n",
    "\n",
    "# import basic plot tools\n",
    "from qiskit.tools.visualization import plot_histogram"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:28.659863Z",
     "start_time": "2018-09-29T01:22:28.657315Z"
    }
   },
   "outputs": [],
   "source": [
    "backend = BasicAer.get_backend('qasm_simulator') # run on local simulator by default\n",
    "\n",
    "# Uncomment the following lines to run on a real device\n",
    "#IBMQ.load_account()\n",
    "#from qiskit.providers.ibmq import least_busy\n",
    "#backend = least_busy(IBMQ.backends(operational=True, simulator=False))\n",
    "#print(\"the best backend is \" + backend.name())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Quantum States - Basis States and Superpositions<a id='section1'></a>\n",
    "\n",
    "The first Principle above tells us that the results of measuring a quantum state may be random or deterministic, depending on what basis is used. To demonstrate, we will first introduce the computational (or standard) basis for a qubit. \n",
    "\n",
    "The computational basis is the set containing the ground and excited state $\\{|0\\rangle,|1\\rangle\\}$, which also corresponds to the following vectors: \n",
    "\n",
    "$$|0\\rangle =\\begin{pmatrix} 1 \\\\ 0 \\end{pmatrix}$$\n",
    "$$|1\\rangle =\\begin{pmatrix} 0 \\\\ 1 \\end{pmatrix}$$\n",
    "\n",
    "In Python these are represented by"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:31.126309Z",
     "start_time": "2018-09-29T01:22:31.123639Z"
    }
   },
   "outputs": [],
   "source": [
    "zero = np.array([[1],[0]])\n",
    "one = np.array([[0],[1]])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In our quantum processor system (and many other physical quantum processors) it is natural for all qubits to start in the $|0\\rangle$ state, known as the ground state. To make the $|1\\rangle$ (or excited) state, we use the operator \n",
    "\n",
    "$$ X =\\begin{pmatrix} 0 & 1 \\\\ 1 & 0 \\end{pmatrix}.$$\n",
    "\n",
    "This $X$ operator is often called a bit-flip because it exactly implements the following:\n",
    "\n",
    "$$X: |0\\rangle  \\rightarrow  |1\\rangle$$\n",
    "$$X: |1\\rangle \\rightarrow |0\\rangle.$$\n",
    "\n",
    "In Python this can be represented by the following:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:31.755806Z",
     "start_time": "2018-09-29T01:22:31.744374Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0]\n",
      " [1]]\n",
      "[[1]\n",
      " [0]]\n"
     ]
    }
   ],
   "source": [
    "X = np.array([[0,1],[1,0]])\n",
    "print(np.dot(X,zero))\n",
    "print(np.dot(X,one))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next, we give the two quantum circuits for preparing and measuring a single qubit in the ground and excited states using Qiskit."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:32.680270Z",
     "start_time": "2018-09-29T01:22:32.669604Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<qiskit.circuit.measure.Measure at 0x124aacb70>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Creating registers\n",
    "qr = QuantumRegister(1)\n",
    "cr = ClassicalRegister(1)\n",
    "\n",
    "# Quantum circuit ground \n",
    "qc_ground = QuantumCircuit(qr, cr)\n",
    "qc_ground.measure(qr[0], cr[0])\n",
    "\n",
    "# Quantum circuit excited \n",
    "qc_excited = QuantumCircuit(qr, cr)\n",
    "qc_excited.x(qr)\n",
    "qc_excited.measure(qr[0], cr[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:34.044630Z",
     "start_time": "2018-09-29T01:22:33.056545Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPEAAAB2CAYAAAAZfnVpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAKd0lEQVR4nO3dbWyT5RoH8H+3AXVbu+6syGScbqfTZUFYWsYchxPsmELDGE6QfZiEZB/INHwwZKirGiN+gHS+JErONJIRxwk20cA5bsZEZoIsMWKNzmIwfjhz7M1jsuJJ1zKS6cp1Phh7GOu6Dto+vbf/L1nSPL2f57pa+ud+2rsvOhEREJGyMrRugIjuDENMpDiGmEhxDDGR4hhiIsUxxESKY4iJFMcQEymOISZSHENMpDiGmEhxDDGR4hhiIsUxxESKY4iJFMcQEymOISZSHENMpDiGmEhxDDGR4hhiIsUxxESKY4iJFMcQEymOISZSHENMpLgsrRugxevQoUPw+Xwpr2uz2fDGG2+kvK5WOBNT0vh8vpSHWIuaWuNMTElls9lw4cKFlNWrqalJWa10wZmYSHEMMZHiGGIixTHERIpjiIkUxxBT2gmHw5iamoKIzDt2eHg4BR2lN4aYNDc1NQWPx4PGxkZYrVZkZWVBr9cjOzsbmzZtQmtrK77//vtZ+3366acoLy/HyZMnNeg6fSypEHd1dS1oHbGyshLnzp1LXkNLnIjg5MmTsFgs2LdvH7xeLzZu3IiXXnoJR48exZNPPokVK1ago6MD69atg9PpxODgIIDfA/zII4/gvvvuQ0NDg8a3RGOSpqanp+Xpp58Ws9ksubm5smfPHvH7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er4fT6cTo6CgAIC8vb8Y+JpMJwWAQAHD69Gl0dHQAAI4dO4atW7dGreNyueByueLuKxQKzVs7mVztJ5JeQzXHu/6pdQtpI9aPyqU8xH19fdDpdGhoaJh1ncFgAABMTEzM2B4IBGA0GhEIBPDaa6/hyy+/xLVr1/Dwww+jv78fGRl3fkIxX+1k4y//zSQinIXjlPLT6atXryI/Pz/qP5DJZILFYkF/f39k2+DgIILBICoqKuD1euFwOKDX62E2m7F69WoMDQ0lpK/5alNqMcDxS/lMvGHDBly5cgUfffQRdu7ciWAwCK/XC6fTCQBoaWlBe3s7tm7dioKCArS1tcHpdKKkpARffPEF8vPzI8fKz8/HL7/8AqvVmpDeYtVONp5OUywxz9S0eDWtq6tLysrKJCcnRwoLC+X555+PXDc9PS2HDx+WgoICyc3Nld27d4vf7xcRkU8++USeeuqpyNi6ujr58ccfo9Y4evSorF27dkF9xapNlK6U+hRTIBBAbW0tLl68iMnJSdTW1ibsOTGRqpT6YKbJZMKhQ4dQU1MDAHj99dcZYFrylJqJiWg2TmNEimOIiRTHEBMpjiEmUhxDTKQ4hphIcQwxkeIYYiLFMcREimOIiRTHEBMpjiEmUhxDTKQ4hphIcQwxkeIYYiLFMcREimOIiRTHEBMpjiEmUhxDTKQ4hphIcQwxkeL+BxT664Qkj3+0AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 301x138.46 with 1 Axes>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc_ground.draw(output='mpl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:35.206121Z",
     "start_time": "2018-09-29T01:22:34.046699Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAR8AAAB2CAYAAADx25drAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29md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/ejN27d6OnpwfXr1/Hzp07Ybfb0dXVhaysLM/YRYsWQaVS4erVq37VMJvNyMjw/T13IGvT1HL30vtqKABkrljMS+s+CvmbUpfLhV27dqG6uhqbNm0CAMTFxcFgMOD69esAgMTExBH7qNVqOBwOAEBtbS2OHj0KADh48CDy8vJGrWMymWAymXzuy+l0eq0dTKbKqqDXoOBraf0ZLa0/y24jbJiNpWM+F/LwsVgsUCgUKCoquu85pfLuibv+/v4R2+12O1QqFex2O959911cuXIFt27dwtq1a9HS0oKoqAdfwHmrHWzjfZMoMgghoFD4cushARJOOPf19SEpKWnUb5JarUZaWhpaWlo829ra2uBwOJCRkQGr1Qq9Xo+4uDjMnDkT8+bNQ0dHR0D68labyBsGj39CvvLJzMxEe3s7zp49iw0bNsDhcMBqtcJgMAAASktLUVlZiby8PCQnJ8NoNMJgMGDhwoVobm5GUlKS57WSkpLw22+/IT09PSC9jVc72Pi2iyajcVf0Ms5yHzt2TCxZskTEx8eLOXPmiH379nmeGxoaEmVlZSI5OVkkJCSIzZs3i97eXiGEEI2NjeKll17yjF2/fr345ZdfRq1x4MABsXz5cr/6Gq82EQVWRP1Vu91uR35+Pi5fvgyXy4X8/PyAnfMhotCKqFsw1Wo19u7di9zcXADAoUOHGDxEESqiVj5ENHlw2UBEUjB8iEgKhg8RScHwISIpGD5EJAXDh4ikYPgQkRQMHyKSguFDRFIwfIhICoYPEUnB8CEiKRg+RCQFw4eIpGD4EJEUDB8ikoLhQ0RSMHyISAqGDxFJwfAhIikYPkQkBcOHiKRg+BCRFP8Bbe0kCnBuRKwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 361.2x138.46 with 1 Axes>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc_excited.draw(output='mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here we have created two jobs with different quantum circuits; the first to prepare the ground state, and the second to prepare the excited state. Now we can run the prepared jobs."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:35.409157Z",
     "start_time": "2018-09-29T01:22:35.212330Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "circuits = [qc_ground, qc_excited]\n",
    "job = execute(circuits, backend)\n",
    "result = job.result()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After the run has been completed, the data can be extracted from the API output and plotted."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:35.607490Z",
     "start_time": "2018-09-29T01:22:35.414354Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAc0AAAEyCAYAAACYgYvRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAYmklEQVR4nO3de7SddX3n8ffXgwzJEkJyPE3OiabN0YpHpYeQMJUgEC5xFBwXQhfEG6JFBhW8INYwY63YomuiIoyWUWi7EHSAgtpaGwYIScWCCrlgg3FSg5gUclFyURqJCfidP54durNzLr99OJdNzvu11l5nP7/n9/z29/nnfNZz+z2RmUiSpME9b6wLkCTpucLQlCSpkKEpSVIhQ1OSpEKGpiRJhQxNSZIKHTTWBYyl9vb2nDFjxliXIUlqIQ8++ODjmdnR17pxHZozZsxg6dKlY12GJKmFTJkyZX1/6zw9K0lSIUNTkqRChqYkSYUMTUmSChmakiQVMjQlSSpkaEqSVMjQlCSpkKEpSVIhQ1OSpEKGpiRJhQxNSZIKGZqSJBUyNCVJKmRoSpJUyNCUJKmQoSlJUiFDU5KkQoamJEmFDE1JkgoZmpIkFTI0JUkqZGhKB6CLLrqIl73sZcydO7fP9ZnJwoULmT17Nq95zWv44Q9/+My6m266iTlz5jBnzhxuuummZ9offPBBjjvuOGbPns3ChQvJzBHfD6nVGJrSAegtb3kLt956a7/rlyxZwsMPP8zy5cv5/Oc/z4c//GEAtm/fzqJFi7jrrrtYsmQJixYtYseOHQBceumlXHXVVSxfvpyHH36YJUuWjMq+SK3E0JQOQHPnzmXy5Mn9rl+8eDELFiwgIjjmmGP41a9+xebNm1m6dCnz5s1j8uTJHH744cybN4+7776bzZs388QTT3DMMccQESxYsIDFixeP4h5JrcHQlMahTZs2MX369GeWu7q62LRpExs3btyvfePGjWzatImurq79+kvjjaEpSVIhQ1Mahzo7O3nssceeWd64cSOdnZ10dXXt197V1UVnZycbN27cr7803hia0jj0+te/nptvvpnM5IEHHuCwww5j2rRpnHzyySxbtowdO3awY8cOli1bxsknn8y0adM49NBDeeCBB8hMbr75Zk477bSx3g1p1B001gVIGn7nn38+9957L1u3buWVr3wlCxcu5KmnngLgne98J/Pnz+euu+5i9uzZTJgwgS9+8YsATJ48mUsvvZRTTjkFgI985CPP3FD0mc98hve9733s2rWLU089lVNPPXVsdk4aQzGen7WaNWtWLl26dKzLkCS1kClTpqzIzDl9rfP0rCRJhQxNSZIKGZqSJBUyNCVJKmRoSpJUyNCUJKmQoSlJUiFDU5KkQqMamhFxQkR8KyIei4iMiPMKtjkyIr4TEU/Wtvt4RERDn7MiYk1E/Kb2900jthOSpHFrtI80XwA8BHwAeHKwzhFxGHAXsAU4prbdR4BL6vocC9wCfA04qvb31oj4w+EuXpI0vo3q3LOZuRhYDBAR1xds8lZgIvCOzHwSeCgiXg5cEhFXZjUH4AeBZZl5RW2bKyLipFr7m4d7HyRJ41erX9M8FvhuLTD3ugPoAn6vrs+dDdvdAcwd8eokSeNKq7/lZBrwaEPblrp1j9T+bumjz7S+BoyIC4ALoHqn4MqVK4HqTfQTJ05k3bp1AEyaNInu7m5WrVoFQFtbG729vaxdu5adO3cC0NPTw7Zt27h6yaue1U5Kkp69j75hHevXrwego6ODjo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FmXmXWNWoNTCDE1pHImIAJ6gepb5nrq2FwGvBt5NNe/mOZn54JgVKrUor2lK48srgEeA3XsbsvJvmXkr8AaqUD1njOqTWpqhKY0vPwV+Dny+dhPQPv8DavM5fwV4/VgUJ7U6Q1MaRzLzSeB/ABOAG4BzI+LFEfECgIiYCJxINR2lpAZe05TGoYh4FfCnwBuBnVRvFPoFcCrVnbTnZ+bqsatQak2GpjSO1R4/OR04A9hFdYR5a2b+vzEtTGpRhqYkACLieZn527GuQ2plhqYkSYW8EUiSpEKGpiRJhQxNSZIKGZqSJBUyNCVJKmRoSpJUyNCUJKnQ/wcY31yKX0a0RwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plot_histogram(result.get_counts(qc_ground))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:35.889118Z",
     "start_time": "2018-09-29T01:22:35.612309Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAc0AAAEyCAYAAACYgYvRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAYh0lEQVR4nO3da5SdVZ3n8e/fwgzJEkJS1CRVsdOd0hZrIV2EhOkmCIRLHMUel4ILgtqIN4arIqKGWbaK0+paQRFGm1Ho7sVFB2hQu207NCEkLXRAIBc0ECdtaEhGclGSitqRWAH/8+Kc0Ccnddkn1OWQ+n7WOqueZz9772c/b/LLc9tPZCaSJGlwrxjtAUiS9HJhaEqSVMjQlCSpkKEpSVIhQ1OSpEKGpiRJhQ4a7QGMptbW1pw+ffpoD0OS1EQee+yxZzOz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5G+PHsNcGtEPAIsp/J0bAfwdYCIuAUgM8+t1v86cElEXAt8AzgeOA84p7RPSZKGyoiGZmbeERGtwKeAduBx4PTM3FCtMr2u/lMRcTrwFSqvkGwCPpyZ326gT0llvG0hDSIyc7THIEnSy4Jzz0qSVMjQlCSpkKEpSVIhQ1OSpEKGpiRJhQxNaYyJiEMjIkZ7HNLLkaEpjT1XA++PiKMi4tC+KlTffZZUx/c0pTEkIs4BvgX8CtgO3Av8E/BjKt+ufS4ixgO3AX+emWtGbbBSEzI0pTEkIm6k8pGDhcAZwHuB1wDrgEXAfcARwHWZOW60xik1K0NTGiMi4iDgE8ChmbmgpvxI4EPAO4GDgcOAmzPzA6MyUKmJGZrSGBIRk4Apmfl/I2IcsDtr/hGIiLOpXJo9JjMfG61xSs1qzH2EWhrLMrMH6Kku9wJExCuo/Af6BeBQYJeBKfXN0JTGuMz8Xc3qIcBnRmssUrPz8qykF0XEK4EX6oJUUpWhKUlSISc3kCSpkKEpSVIhQ1OSpEKGpiRJhQxNSZIKGZqSJBX6/wpaOwEr/u8pAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plot_histogram(result.get_counts(qc_excited))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here we see that the qubit is in the $|0\\rangle$ state with 100% probability for the first circuit and in the $|1\\rangle$ state with 100% probability for the second circuit. If we had run on a quantum processor rather than the simulator, there would be a difference from the ideal perfect answer due to a combination of measurement error, preparation error, and gate error (for the $|1\\rangle$ state). \n",
    "\n",
    "Up to this point, nothing is different from a classical system of a bit. To go beyond, we must explore what it means to make a superposition. The operation in the quantum circuit language for generating a superposition is the Hadamard gate, $H$. Let's assume for now that this gate is like flipping a fair coin. The result of a flip has two possible outcomes, heads or tails, each occurring with equal probability. If we repeat this simple thought experiment many times, we would expect that on average we will measure as many heads as we do tails. Let heads be $|0\\rangle$ and tails be $|1\\rangle$. \n",
    "\n",
    "Let's run the quantum version of this experiment. First we prepare the qubit in the ground state $|0\\rangle$. We then apply the Hadamard gate (coin flip). Finally, we measure the state of the qubit. Repeat the experiment 1024 times (shots). As you likely predicted, half the outcomes will be in the $|0\\rangle$ state and half will be in the $|1\\rangle$ state.\n",
    "\n",
    "Try the program below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:37.057180Z",
     "start_time": "2018-09-29T01:22:35.893424Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"word-wrap: normal;white-space: pre;line-height: 15px;\">         ┌───┐┌─┐\n",
       "q0_0: |0>┤ H ├┤M├\n",
       "         └───┘└╥┘\n",
       " c0_0: 0 ══════╩═\n",
       "                 </pre>"
      ],
      "text/plain": [
       "<qiskit.visualization.text.TextDrawing at 0x124e9c1d0>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Quantum circuit superposition \n",
    "qc_superposition = QuantumCircuit(qr, cr)\n",
    "qc_superposition.h(qr)\n",
    "qc_superposition.measure(qr[0], cr[0])\n",
    "\n",
    "qc_superposition.draw()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:37.261227Z",
     "start_time": "2018-09-29T01:22:37.059186Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAc0AAAEyCAYAAACYgYvRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3df5jWdZ3v8edbBAQDZIDFGV1AhGj4EY2YaauYmUbucUu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uPuu+/mM5/5DADf/va3Wb58OV//+tcP3I6yatUqAO666y5mzZrF5s2bOe+887jxxhv7bRuPBj4azEeDSZLa8dFgkiT1AENTkqSCDE1JkgoyNCVJKsjQlCSpIENTkqSCDE1JkgoyNCVJKsjQlCSpIENTkqSCDE1JkgoyNI9xDz/8MGeddRbz5s3jjjvu6LLfd7/7Xaqqqli5ciUADz744IGJn+fPn8+4ceMOTAC9ZMkSzj33XM455xxuu+22vtgMSeoTx/d3Aeo/bW1t3HzzzSxZsoSamhouvPBCFixYwCte8YqD+u3atYu77rqLefPmHWh729vextve9jYA1qxZw7ve9S7mzJnDtm3b+OhHP8ojjzzC+PHjuf766/nRj37E+eef36fbJnXn5i+P7e8S1AsWX7O913+He5rHsBUrVnDaaacxZcoUhg0bxsKFCw88Yqi9RYsW8f73v58TTjih03G++c1vsnDhQgDWr1/P6aefzvjx4wE4//zz+d73vtd7GyFJfcjQPIY1NzdzyimnHPhcU1NDc3PzQX3q6+t5+umnufjii7sc51vf+taB0Jw6dSpr165l48aNvPDCC/zgBz846GnzknQ08/CsuvTiiy9y6623HniQbWd+8YtfMGLECGbOnAnASSedxO2338573vMejjvuOM466yzWr1/fRxVLUu8yNI9h1dXVB+0Fbt68merq6gOff/vb39LQ0MCll14KwK9//WuuvPJKvvrVr1JXVweULvp561vfetC4CxYsYMGCBQDce++9DBkypLc3RZL6hIdnj2FnnHEGTU1NbNiwgdbWVpYsWXIg7ABGjx7NunXrqK+vp76+njPPPPOgwHzxxRf5zne+c+DQ7H4tLS0A/OY3v+GLX/wiV111Vd9tlCT1Ivc0j2HHH388ixcv5vLLL6etrY0rr7yS2tpaFi1aRF1dHW9605u6XX/58uXU1NQwZcqUg9pvueUWVq9eDcAHP/hBpk2b1lubIEl9KjKzv2voN3V1dbls2bL+LkNSH/OWk8Gpp245qaqqWpGZZ3a2zMOzkiQVZGhKklSQoSlJUkGGpiRJBRmakiQVZGhKklSQoSlJUkGGpiRJBRmakiQVZGhKklSQoSlJUkFO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WpikbkXEcZT+nW+LiD+ldGh2ZH/XdTQzNFWRiDiu4/lNSQNfRNwEDMnMv+vvWo5mhqYkHQMiYijQ5v/0HhlDU5Kkgrx6VpKkggxNSZIKMjQlSSrI0JQkqep8VDMAAAARSURBVCBDU5KkggxNSZIK+v8hJgCiJPpINQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job = execute(qc_superposition, backend, shots = 1024)\n",
    "result = job.result()\n",
    "\n",
    "plot_histogram(result.get_counts(qc_superposition))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Indeed, much like a coin flip, the results are close to 50/50 with some non-ideality due to errors (again due to state preparation, measurement, and gate errors). So far, this is still not unexpected. Let's run the experiment again, but this time with two $H$ gates in succession. If we consider the $H$ gate to be analog to a coin flip, here we would be flipping it twice, and still expecting a 50/50 distribution. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:38.451858Z",
     "start_time": "2018-09-29T01:22:37.266684Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAB2CAYAAADGFVhfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAANIUlEQVR4nO3dfUxT5x4H8C8vXtBrS7mA7DplrHqJCmIRKpv3OgR11alhDDHZi8u2GNwcyZhC2mxm022SgpvMuzkTRiJL0D9UImhMnNlb/xjadCPAhjO5rAriyHVMSjuMukHvH146O6Av2va0T7+fxIScPqe/Xx/il9PT55xG2O12O4iISFiRUjdARET+xaAnIhIcg56ISHAMeiIiwTHoiYgEx6AnI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14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Quantum circuit two Hadamards \n",
    "qc_twohadamard = QuantumCircuit(qr, cr)\n",
    "qc_twohadamard.h(qr)\n",
    "qc_twohadamard.barrier()\n",
    "qc_twohadamard.h(qr)\n",
    "qc_twohadamard.measure(qr[0], cr[0])\n",
    "\n",
    "qc_twohadamard.draw(output='mpl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:38.640465Z",
     "start_time": "2018-09-29T01:22:38.458190Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAc0AAAEyCAYAAACYgYvRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAYmklEQVR4nO3de7SddX3n8ffXgwzJEkJyPE3OiabN0YpHpYeQMJUgEC5xFBwXQhfEG6JFBhW8INYwY63YomuiIoyWUWi7EHSAgtpaGwYIScWCCrlgg3FSg5gUclFyURqJCfidP54durNzLr99OJdNzvu11l5nP7/n9/z29/nnfNZz+z2RmUiSpME9b6wLkCTpucLQlCSpkKEpSVIhQ1OSpEKGpiRJhQxNSZIKHTTWBYyl9vb2nDFjxliXIUlqIQ8++ODjmdnR17pxHZozZsxg6dKlY12GJKmFTJkyZX1/6zw9K0lSIUNTkqRChqYkSYUMTUmSChmakiQVMjQlSSpkaEqSVMjQlCSpkKEpSVIhQ1OSpEKGpiRJhQxNSZIKGZqSJBUyNCVJKmRoSpJUyNCUJKmQoSlJUiFDU5KkQoamJEmFDE1JkgoZmpIkFTI0JUkqZGhKB6CLLrqIl73sZcydO7fP9ZnJwoULmT17Nq95zWv44Q9/+My6m266iTlz5jBnzhxuuummZ9offPBBjjvuOGbPns3ChQvJzBHfD6nVGJrSAegtb3kLt956a7/rlyxZwsMPP8zy5cv5/Oc/z4c//GEAtm/fzqJFi7jrrrtYsmQJixYtYseOHQBceumlXHXVVSxfvpyHH36YJUuWjMq+SK3E0JQOQHPnzmXy5Mn9rl+8eDELFiwgIjjmmGP41a9+xebNm1m6dCnz5s1j8uTJHH744cybN4+7776bzZs388QTT3DMMccQESxYsIDFixeP4h5JrcHQlMahTZs2MX369GeWu7q62LRpExs3btyvfePGjWzatImurq79+kvjjaEpSVIhQ1Mahzo7O3nssceeWd64cSOdnZ10dXXt197V1UVnZycbN27cr7803hia0jj0+te/nptvvpnM5IEHHuCwww5j2rRpnHzyySxbtowdO3awY8cOli1bxsknn8y0adM49NBDeeCBB8hMbr75Zk477bSx3g1p1B001gVIGn7nn38+9957L1u3buWVr3wlCxcu5KmnngLgne98J/Pnz+euu+5i9uzZTJgwgS9+8YsATJ48mUsvvZRTTjkFgI985CPP3FD0mc98hve9733s2rWLU089lVNPPXVsdk4aQzGen7WaNWtWLl26dKzLkCS1kClTpqzIzDl9rfP0rCRJhQxNSZIKGZqSJBUyNCVJKmRoSpJUyNCUJKmQoSlJUiFDU5KkQqMamhFxQkR8KyIei4iMiPMKtjkyIr4TEU/Wtvt4RERDn7MiYk1E/Kb2900jthOSpHFrtI80XwA8BHwAeHKwzhFxGHAXsAU4prbdR4BL6vocC9wCfA04qvb31oj4w+EuXpI0vo3q3LOZuRhYDBAR1xds8lZgIvCOzHwSeCgiXg5cEhFXZjUH4AeBZZl5RW2bKyLipFr7m4d7HyRJ41erX9M8FvhuLTD3ugPoAn6vrs+dDdvdAcwd8eokSeNKq7/lZBrwaEPblrp1j9T+bumjz7S+BoyIC4ALoHqn4MqVK4HqTfQTJ05k3bp1AEyaNInu7m5WrVoFQFtbG729vaxdu5adO3cC0NPTw7Zt27h6yaue1U5Kkp69j75hHevXrwego6ODjo4O1qxZA8CECRPo6elh9erV7NmzB4De3l42bNjA9u3bAeju7mb37t0D/karh+awy8xrgWu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gEeA3XsbsvJvmXkr8AaqUD1njOqTWpqhKY0vPwV+Dny+dhPQPv8DavM5fwV4/VgUJ7U6Q1MaRzLzSeB/ABOAG4BzI+LFEfECgIiYCJxINR2lpAZe05TGoYh4FfCnwBuBnVRvFPoFcCrVnbTnZ+bqsatQak2GpjSO1R4/OR04A9hFdYR5a2b+vzEtTGpRhqYkACLieZn527GuQ2plhqYkSYW8EUiSpEKGpiRJhQxNSZIKGZqSJBUyNCVJKmRoSpJUyNCUJKnQ/wcY31yKX0a0RwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job = execute(qc_twohadamard, backend)\n",
    "result = job.result()\n",
    "\n",
    "plot_histogram(result.get_counts(qc_twohadamard))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This time, the results are surprising. Unlike the classical case, with high probability the outcome is not random, but in the $|0\\rangle$ state. *Quantum randomness* is not simply like a classical random coin flip. In both of the above experiments, the system (without noise) is in a definite state, but only in the first case does it behave randomly. This is because, in the first case, via the $H$ gate, we make a uniform superposition of the ground and excited state, $(|0\\rangle+|1\\rangle)/\\sqrt{2}$, but then follow it with a measurement in the computational basis. The act of measurement in the computational basis forces the system to be in either the $|0\\rangle$ state or the $|1\\rangle$ state with an equal probability (due to the uniformity of the superposition). In the second case, we can think of the second $H$ gate as being a part of the final measurement operation; it changes the measurement basis from the computational basis to a *superposition* basis. The following equations illustrate the action of the $H$ gate on the computational basis states:\n",
    "$$H: |0\\rangle  \\rightarrow  |+\\rangle=\\frac{|0\\rangle+|1\\rangle}{\\sqrt{2}}$$\n",
    "$$H: |1\\rangle \\rightarrow |-\\rangle=\\frac{|0\\rangle-|1\\rangle}{\\sqrt{2}}.$$\n",
    "We can redefine this new transformed basis, the superposition basis, as the set {$|+\\rangle$, $|-\\rangle$}. We now have a different way of looking at the second experiment above. The first $H$ gate prepares the system into a superposition state, namely the $|+\\rangle$ state. The second $H$ gate followed by the standard measurement changes it into a measurement in the superposition basis. If the measurement gives 0, we can conclude that the system was in the $|+\\rangle$ state before the second $H$ gate, and if we obtain 1, it means the system was in the $|-\\rangle$ state. In the above experiment we see that the outcome is mainly 0, suggesting that our system was in the $|+\\rangle$ superposition state before the second $H$ gate. \n",
    "\n",
    "\n",
    "The math is best understood if we represent the quantum superposition state $|+\\rangle$ and $|-\\rangle$ by: \n",
    "\n",
    "$$|+\\rangle =\\frac{1}{\\sqrt{2}}\\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}$$\n",
    "$$|-\\rangle =\\frac{1}{\\sqrt{2}}\\begin{pmatrix} 1 \\\\ -1 \\end{pmatrix}$$\n",
    "\n",
    "A standard measurement, known in quantum mechanics as a projective or von Neumann measurement, takes any superposition state of the qubit and projects it to either the state $|0\\rangle$ or the state $|1\\rangle$ with a probability determined by:\n",
    "\n",
    "$$P(i|\\psi) = |\\langle i|\\psi\\rangle|^2$$ \n",
    "\n",
    "where $P(i|\\psi)$ is the probability of measuring the system in state $i$ given preparation $\\psi$.\n",
    "\n",
    "We have written the Python function ```state_overlap``` to return this: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:38.652365Z",
     "start_time": "2018-09-29T01:22:38.646795Z"
    }
   },
   "outputs": [],
   "source": [
    "state_overlap = lambda state1, state2: np.absolute(np.dot(state1.conj().T,state2))**2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now that we have a simple way of going from a state to the probability distribution of a standard measurement, we can go back to the case of a superposition made from the Hadamard gate. The Hadamard gate is defined by the matrix:\n",
    "\n",
    "$$ H =\\frac{1}{\\sqrt{2}}\\begin{pmatrix} 1 & 1 \\\\ 1 & -1 \\end{pmatrix}$$\n",
    "\n",
    "The $H$ gate acting on the state $|0\\rangle$ gives:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:38.817423Z",
     "start_time": "2018-09-29T01:22:38.658590Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAc0AAAE3CAYAAADITBpiAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAdaUlEQVR4nO3de5hddX3v8feXJBMSmpCZmA4zYoghMQZI40DaCihyiwfo5RHkgB6qWGt5EAstHKR4jlXoBU9jtVCPFKEXCFbkYFGrNYccDC0VVDSENLdOg4GkYSYxhBAiuUwyfM8fe4cOw8xk7cmePTuT9+t59pO9f+u3fvPdGVY+rNtvRWYiSZIO7IjhLkCSpEOFoSlJUkGGpiRJBRmakiQVZGhKklSQoSlJUkGGpiRJBdU8NCPiqoh4JiJ2R8TSiHjnAfo3RMQfltfZExEbIuKaXn3eGxGry8tXR8SFQ/stJEmHo5qGZkRcCtwG3AK0AY8DiyJi6gCrfRU4D7gCmAX8V+Bfe4x5KnA/8HfA28p/PhARvzwU30GSdPiKWs4IFBE/BP41M3+7R9ta4GuZ+Yk++r8beAA4PjOf72fM+4GmzJzfo+1hYEtmvr/a30GSdPiq2Z5mRDQApwCLey1aDJzWz2rvAX4EXBcRGyNibUT8RUT8XI8+p/Yx5kMDjClJ0qCMruHPegMwCtjcq30zcG4/60wH3gHsAd4LTAK+ALQCF5f7HNPPmMf0NWBEXEHpUC/jxo075U1vehMAY8aM4YgjjmDPnj0AjBo1ioaGBnbt2vXquuPHj2f37t288sorABx55JHs27ePffv2vTpGRNDV1dXnGBHBuHHj2LVrF/v38HuP0dDQAPCaMcaMGcPu3bsHHGPv3r10d3f3Ocbo0aMZPXr0gGOMGzeOrq6u14yRmezdu7fPMY444giOPPJIdu7c+erf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qTxFxN3AC8G1gKzAZeBswG9gILMjM/zdsBUrSMDA09ToREcAO4IIetwMFcCzwduC3Kc3NeGlmPjVshUp6jYiYCOxI/2EfMp7TVF9OAJ4BuvY3ZMl/ZOYDwK9SCtVLh6k+SX37LPDhiJhTDtDXiYjJNa5pRDE01Zd1wE+BPy9fBPSa/07K0xfeA5w/HMVJer2IeD+lo0CfA74JfDYiLoyI4yNiXLnPOOCvI2LOMJZ6SPPwrPoUEW+nNBXhLkpTGH4X2JaZP4uI8cBCYHdm/sYwlimpLCLuovQAiwXARcDlwPFAO/AdStvwLOC2zGwYrjoPdYam+hURJwF/APw68DKlCfS3UHpWaSfwkcxcMXwVSgKIiNGUphKdmJk39mg/kdLe58XAkcAk4J7M/K1hKXQEMDR1QOXbT34FeA+wm9L8vg9k5r8Na2GSXhURjUBzZv5bRDQAe3teEBQRlwL3ASd7Ad/gGZqqSEQckZmvDHcdkg6sfD1CZGZ3RPw2pUOz44e7rkNZrR8NpkOcgSkdOnptrxOATw9XLSOFe5qSdBiIiDFAt//je3AMTUmSCvI+TUmSCjI0JUkqyNCUJKkgQ1OSpIIMTUmSCvr/EJn3T4TBddcAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Hadamard = np.array([[1,1],[1,-1]],dtype=complex)/np.sqrt(2)\n",
    "psi1 = np.dot(Hadamard,zero)\n",
    "P0 = state_overlap(zero,psi1)\n",
    "P1 = state_overlap(one,psi1)\n",
    "plot_histogram({'0' : P0.item(0), '1' : P1.item(0)})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "which is the ideal version of the first superposition experiment. \n",
    "\n",
    "The second experiment involves applying the Hadamard gate twice. While matrix multiplication shows that the product of two Hadamards is the identity operator (meaning that the state $|0\\rangle$ remains unchanged), here (as previously mentioned) we prefer to interpret this as doing a measurement in the superposition basis. Using the above definitions, you can show that $H$ transforms the computational basis to the superposition basis."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-29T01:22:38.830023Z",
     "start_time": "2018-09-29T01:22:38.820575Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.70710678+0.j]\n",
      " [0.70710678+0.j]]\n",
      "[[ 0.70710678+0.j]\n",
      " [-0.70710678+0.j]]\n"
     ]
    }
   ],
   "source": [
    "print(np.dot(Hadamard,zero))\n",
    "print(np.dot(Hadamard,one))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is just the beginning of how a quantum state differs from a classical state. Please continue to [Amplitude and Phase](amplitude_and_phase.ipynb) to explore further!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
